﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace Soat.SoPrism.TemplateWizards.Helpers
{
    public class DelegateCommand<T> : DelegateCommand
    {
        public ExecuteEventHandler<T> ExecuteEventHandler { get; private set; }
        public CanExecuteEventHandler<T> CanExecuteEventHandler { get; private set; }

        public DelegateCommand(ExecuteEventHandler<T> executeEventHandler)
            : this(executeEventHandler, null)
        {

        }

        public DelegateCommand(ExecuteEventHandler<T> executeEventHandler, CanExecuteEventHandler<T> canExecuteEventHandler)
        {
            ExecuteEventHandler = executeEventHandler;
            CanExecuteEventHandler = canExecuteEventHandler;
        }


        public override bool CanExecute(object parameter)
        {
            if (null == CanExecuteEventHandler)
            {
                return true;
            }
            return CanExecuteEventHandler((T)parameter);
        }

        public override void Execute(object parameter)
        {
            if (null != ExecuteEventHandler)
            {
                ExecuteEventHandler((T)parameter);
            }
        }

        public override string ExecuteTargetName
        {
            get
            {
                return ExecuteEventHandler.Method.Name;
            }
        }

        public override string CanExecuteTargetName
        {
            get
            {
                return CanExecuteEventHandler.Method.Name;
            }
        }

        public override Type ExecuteTargetType
        {
            get
            {
                return ExecuteEventHandler.Target.GetType();
            }
        }

        public override Type CanExecuteTargetType
        {
            get
            {
                return CanExecuteEventHandler.Target.GetType();
            }
        }

    }
}
